package com.mall.server.controller.oms;

import com.mall.model.domain.OmsOrderReturnApply;
import com.mall.model.dto.OmsOrderReturnApplyDto;
import com.mall.model.dto.OmsUpdateStatusDto;
import com.mall.model.vo.CommonPage;
import com.mall.model.vo.CommonResult;
import com.mall.server.service.oms.OmsOrderReturnApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : xyiaao
 * @createDate : 2022/4/2 20:08
 */
@CrossOrigin
@RestController
@RequestMapping("/returnApply")
public class OmsOrderReturnApplyController {


    @Autowired
    private OmsOrderReturnApplyService omsOrderReturnApplyService;

    /**
     * 分页查询退货申请
     *
     * @param omsOrderReturnApplyDto
     * @return
     */
    @GetMapping("/list")
    public CommonResult list(OmsOrderReturnApplyDto omsOrderReturnApplyDto) {

        CommonPage<OmsOrderReturnApply> page = omsOrderReturnApplyService.page(omsOrderReturnApplyDto);
        return CommonResult.success(page);
    }


    /**
     * 获取退货申请详情
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public CommonResult get(@PathVariable("id") Long id) {

        OmsOrderReturnApply omsOrderReturnApply = omsOrderReturnApplyService.getById(id);
        return CommonResult.success(omsOrderReturnApply);
    }


    /**
     * 修改退货申请状态
     *
     * @param omsUpdateStatusDto
     * @return
     */
    @PostMapping("/update/status/{id}")
    public CommonResult updateStatus(@PathVariable("id") Long id, @RequestBody OmsUpdateStatusDto omsUpdateStatusDto) {

        omsOrderReturnApplyService.updateStatus(id, omsUpdateStatusDto);
        return CommonResult.success();
    }


    /**
     * 批量删除退货申请
     *
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public CommonResult delete(@RequestParam List<Long> ids) {

        omsOrderReturnApplyService.delete(ids);
        return CommonResult.success();
    }

}
